package com.pgytesting.secondhandcar.controller.mcpcar;

import java.util.Map;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.pgytesting.secondhandcar.model.ContractMaterial;
import com.pgytesting.secondhandcar.model.LoanMaterial;
import com.pgytesting.secondhandcar.model.Pagination;
import com.pgytesting.secondhandcar.service.ContractMaterialService;
import com.pgytesting.secondhandcar.service.LoanMaterialService;
import com.pgytesting.secondhandcar.vo.ResponseMessage;

@RestController
@RequestMapping("/sales/review")
public class ReviewController {

    @Autowired
    private ContractMaterialService contractMaterialService;
    @Autowired
    private LoanMaterialService loanMaterialService;


    /**
     * 上传合同材料
     *
     * @return
     */
    @RequestMapping(value = "/insertContractMaterial")
    public ResponseMessage insertContractMaterial(@RequestBody Map<String, Object> paraMap) {
        try {
            if (paraMap.get("contractMaterial") == null) {
                return ResponseMessage.errorResponse("合同材料不能为空");
            }
            if (paraMap.get("id") == null) {
                return ResponseMessage.errorResponse("审核id不能为空");
            }

            contractMaterialService.insert(paraMap);
            return ResponseMessage.successResponse("上传合同完成");
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseMessage.errorResponse("上传合同出现异常");
        }
    }

    /**
     * 上传放款材料
     *
     * @return
     */
    @RequestMapping(value = "/insertLoanMaterial")
    public ResponseMessage insertLoanMaterial(@RequestBody Map<String, Object> paraMap) {
        try {
            if (paraMap.get("loanMaterial") == null) {
                return ResponseMessage.errorResponse("放款材料不能为空");
            }
            if (paraMap.get("id") == null) {
                return ResponseMessage.errorResponse("审核id不能为空");
            }

            loanMaterialService.insert(paraMap);
            return ResponseMessage.successResponse("上传放款材料完成");
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseMessage.errorResponse("上传放款材料出现异常");
        }
    }
}
